import moment from 'moment'
import * as DT from 'dt-sdk'
import { viewer } from '@/components/dt-scene/index.vue'
import { getEleImg } from '@/api/radiation-risk/risk-display'
const state = {
  type: 1,  // 球壳类型
  satId: '',  // 卫星 ID,
  scoreData:[],//
}

const mutations = {
  // 设置球壳类型
  SET_TYPE: (state, val) => {
    state.type = val

    // getEleImgUrl(state.satId, state.type)
  },
  // 设置卫星ID
  SET_SAT_ID: (state, val) => {
    state.satId = val
    // getEleImgUrl(state.satId, state.type)
  },
  SET_SAT_ScoreData:(state,val)=>{
    state.scoreData = val
    console.log('val111',val);
    

  }
}
/**
  * 查询切换球壳图片
  * @author ZZQ
  * @date 2021-11-22
  * @returns {any}
  */
function getEleImgUrl(satId, type) {
  let params = {
    satId: satId,
    type: type
  }
  if (!viewer) return
  let entity = viewer.dataSourceDisplay._defaultDataSource.entities.getById('risk-zone')
  if (+type === 0) {
    if (entity) {
      viewer.dataSourceDisplay._defaultDataSource.entities.remove(entity)
    }
  } else {
    getEleImg(params).then(res => {
      let { url } = res.data.data
      if (entity) {
        entity.rectangle.material = new DT.Cesium.ImageMaterialProperty({
          image: url,
          transparent: 1
        })
      } else {
        viewer.dataSourceDisplay._defaultDataSource.entities.add({
          id: 'risk-zone',
          rectangle: {
            coordinates: DT.Cesium.Rectangle.fromDegrees(
              -180,
              -90,
              180,
              90,
            ),
            height: 0,
            material: new DT.Cesium.ImageMaterialProperty({
              image: url,
              transparent: 1
            })
          },
        });
      }
    })
  }
}
const actions = {
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
